package main

import (
    "bufio"
    "fmt"
    "goprogramming/ch02/tempconv02"
    "goprogramming/ch02/tempconv03"
    "os"
    "strconv"
)

func main() {
    fmt.Printf("Brrrr! %v\n", tempconv02.AbsoluteZeroC) // "Brrrr! -273.15°C"
    fmt.Println(tempconv02.CToF(tempconv02.BoilingC))   // "212°F"
    fmt.Println(tempconv02.FToC(tempconv02.FreezingC))

    args := os.Args[1:]
    if len(args) == 0 {
        input := bufio.NewScanner(os.Stdin)
        for input.Scan() {
            d, err := strconv.ParseFloat(input.Text(), 64)
            if err != nil {
                fmt.Fprintf(os.Stderr, "err, %s", err)
                os.Exit(1)
            }

            print(d)
        }
    } else {
        for _, aa := range args {
            d, err := strconv.ParseFloat(aa, 64)
            if err != nil {
                fmt.Fprintf(os.Stderr, "err %s", err)
                os.Exit(1)
            }

            print(d)
        }
    }

    fmt.Println(tempconv03.PopCount(10000000000000))

    var u uint8 = 255
    fmt.Println(u, u+1, u*u) // "255 0 1"

    var i int8 = 127
    fmt.Println(i, i+1, i*i) // "127 -128 1"

}

func print(t float64) {
    m := tempconv03.Metre(t)
    f := tempconv03.Foot(t)
    fmt.Printf("%s=%s,%s=%s\n", m, tempconv03.MToF(m), f, tempconv03.FToM(f))
}
